package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.activity.ActivityDTO;
import com.qk.entity.Activity;
import com.qk.management.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/activities")
@SuppressWarnings("all")
public class ActivityController {
    @Autowired
    ActivityService activityService;

    @GetMapping
    public Result listActivity(ActivityDTO activityDto){
        PageResult<Activity> pageResult = activityService.listActivities(activityDto);
        return  Result.success(pageResult);
    }

    @PostMapping
    public Result addActivity(@RequestBody Activity activity){
        activityService.addActivity(activity);
        return Result.success();
    }

    @DeleteMapping("/{id}")
    public Result deleteActivity(@PathVariable("id") Integer id){
        activityService.deleteActivity(id);
        return Result.success();
    }

    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        activityService.updateActivity(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        Activity activity = activityService.getById(id);
        return Result.success(activity);
    }

    @GetMapping("/type/{type}")
    public Result getByType(@PathVariable("type") Integer type){
        List<Activity> list = activityService.getByType(type);
        return Result.success(list);
    }
}
